<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    span {
        display: inline-block;
        width: 100px;
        height: 20px;
        border: 1px red solid;
    }
</style>

<body>
    用户名：<input type="text"><br>
    密码：<input type="text"><br>
    请输入验证码:<input type="text" class="inp"> <button id="verification">获取验证码</button>
    <br>
    <button id="submit">登陆</button>
    <!-- <h6 id="demo">111</h6> -->

    <script src="../js/utils.js"></script>
    <script>

        var inputs = document.getElementsByClassName('inp');
        var ver = document.getElementById('verification');
        var submit = document.getElementById('submit')
        var code = null
        //获取验证码
        ver.onclick = function () {
            code = randomNum(1000, 9999)
            ver.innerHTML = code
        }
        //登陆
        submit.onclick = function () {
            var value = inputs[0].value;
            if (parseInt(value) !== code) {
                alert('验证码错误')
            } else {
                alert('登陆成功')
            }
        }
    </script>
</body>

</html>